import request from '@/config/axios'
import CryptoJS from 'crypto-js'
export interface OrderWithdrawalSummaryVO {
  id: number
  withdrawBatchNo: string
  withdrawAmount: number
  orderCount: number
  applyTime: Date
  paymentTime: Date
  paymentStatus: number
  createBy: string
  updateBy: string
}
export interface OrderWithdrawDkVO {
  id: number
  amount: number,
  remark: '',
  payTime: Date, // 默认当前时间
  receiptUrl: '' // 回单文件 URL
  requestId: string
}

// 查询订单提现汇总分页
export const getOrderWithdrawalSummaryPage = async (params) => {
  return await request.get({ url: `/hotel/order-withdrawal-summary/page`, params })
}

// 查询订单提现汇总详情
export const getOrderWithdrawalSummary = async (id: number) => {
  return await request.get({ url: `/hotel/order-withdrawal-summary/get?id=` + id })
}

// 新增订单提现汇总
export const createOrderWithdrawalSummary = async (data: OrderWithdrawalSummaryVO) => {
  return await request.post({ url: `/hotel/order-withdrawal-summary/create`, data })
}

// 修改订单提现汇总
export const updateOrderWithdrawalSummary = async (data: OrderWithdrawalSummaryVO) => {
  return await request.put({ url: `/hotel/order-withdrawal-summary/update`, data })
}

// 删除订单提现汇总
export const deleteOrderWithdrawalSummary = async (id: number) => {
  return await request.delete({ url: `/hotel/order-withdrawal-summary/delete?id=` + id })
}

// 导出订单提现汇总 Excel
export const handleExportDetail = async (id: number) => {
  return await request.download({
    url: `/hotel/order-withdrawal-summary/handleExportDetail`,
    params: { id }
  })
}


// 回单下载
export const handleExportHd = async (id: number) => {
  return await request
    .get(
      {
        url: `/hotel/order-withdrawal-summary/handleExportHd`,
        params: { id }
      })
}

//财务看板
export const getFinancialDashboard = async () => {
  return await request.get({ url: '/hotel/order-withdrawal-summary/getFinancialDashboard' })
}

export const getByWithdrawBatchNo = async (params) => {
  return await request.get({
    url: '/hotel/order-withdrawal/getByWithdrawBatchNo',
    params
  })
}

export const tgHandle = async (id: number) => {
  return await request.post({
    url: '/hotel/order-withdrawal-summary/tgHandle',
    data: {
      'id': id,
      'requestId': `batchp_${CryptoJS.MD5(String(id))}`
    }
  });
}

export const handleBatchReject = async (ids: number[]) => {
  return await request.post({
    url: '/hotel/order-withdrawal-summary/handleBatchReject',
    data: {
      'ids': ids,
      'requestId': `batchr_${CryptoJS.MD5(ids.join(','))}`
    }
  })

}

export const handleBatchPass = async (ids: number[]) => {
  return await request.post({
    url: '/hotel/order-withdrawal-summary/handleBatchPass',
    data: {
      'ids': ids,
      'requestId': `batchp_${CryptoJS.MD5(ids.join(','))}`
    }
  })
}


export const rejectHandler = async (id: number, rejectReason: string) => {

  return await request.post({
    url: '/hotel/order-withdrawal-summary/rejectHandler',
    data: {
      'id': id,
      'requestId': `batchr_${CryptoJS.MD5(String(id))}`,
      'rejectReason': rejectReason
    }
  });
}

export const dkHandle = async (data: OrderWithdrawDkVO) => {
  return await request.post({
    url: '/hotel/order-withdrawal-summary/dkHandler',
    data
  })
}